package com.ydy.remote.wechat.vo.message;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;

import javax.xml.bind.JAXB;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

import com.alibaba.fastjson.JSONObject;
import com.ydy.remote.wechat.ienum.MsgType;

@XmlRootElement(name = "xml")
public class TextMessage extends BaseMessage {

	{
		setMsgType(MsgType.text.name());
	}
	@XmlElement(name = "Content")
	private String content;

	@XmlTransient
	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public static void main(String[] args) {
		String xml = "<xml>\r\n" + "  <ToUserName><![CDATA[toUser]]></ToUserName>\r\n"
				+ "  <FromUserName><![CDATA[fromUser]]></FromUserName>\r\n"
				+ "  <CreateTime>1348831860</CreateTime>\r\n" + "  <MsgType><![CDATA[text]]></MsgType>\r\n"
				+ "  <Content><![CDATA[this is a test]]></Content>\r\n" + "  <MsgId>1234567890123456</MsgId>\r\n"
				+ "</xml>";
		System.out.println(xml);
		TextMessage text = null;
		text = JAXB.unmarshal(new ByteArrayInputStream(xml.getBytes()), TextMessage.class);
		System.out.println(JSONObject.toJSON(text));
		OutputStream out = new ByteArrayOutputStream();
		JAXB.marshal(text, out);
		System.out.println(out.toString());
	}
}
